﻿using System;
using System.Collections.Generic;
using System.Text;
using NExt.Handler.Base.Common.Manager;
using System.Reflection;
using System.IO;

namespace NExt.Handler.Component.Default.JsSerialize
{
    public class ConstructoRemoteInstanceDecoratorScriptGenerator : AbstractNExtScriptGenerator
    {
        private const string SCRIPT_POSTFIX = "Decoration.js";
        private const string CONFIG_DECORATOR_SCIPT_FORMAT = "{0} = NExt.DecorateRemoteInstance({0}, {1}, '{0}');";

        public ConstructoRemoteInstanceDecoratorScriptGenerator()
            : base(SCRIPT_POSTFIX)
        {
        }

        protected override string BuildDefaultContent(Type type)
        {
            string fullName = type.FullName;
            string assemblyJsName = AssemblyManager.GetJsName(type.Assembly);

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.AppendLine(string.Format(CONFIG_DECORATOR_SCIPT_FORMAT, fullName, assemblyJsName));

            string script = stringBuilder.ToString();
            return script;
        }
    }
}
